package com.ueboot.weishop.service.area.impl;

import com.ueboot.core.repository.BaseRepository;
import com.ueboot.core.service.impl.BaseServiceImpl;
import com.ueboot.weishop.entity.setting.AreaEntity;
import com.ueboot.weishop.repository.area.AreaRepository;
import com.ueboot.weishop.service.area.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Neel on 2017/10/9.
 */
@Slf4j
@Service
public class AreaServiceImpl extends BaseServiceImpl<AreaEntity> implements AreaService {

    @Autowired
    private AreaRepository repository;

    @Override
    public BaseRepository getBaseRepository() {
        return repository;
    }

    @Override
    public List<AreaEntity> findByParentId(Long parentId) {
        return repository.findByParentId(parentId);
    }

    @Override
    public List<AreaEntity> findByFullPathIdStartingWithAndLevel(String fullPathId, Integer level) {
        if (fullPathId == null) {
            return repository.findByLevel(level);
        }
        return repository.findByFullPathIdStartingWithAndLevel(fullPathId, level);
    }

}
